package com.logictech.lims.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.Pagenation;

import com.logictech.lims.service.LogService;
import com.logictech.lims.service.ReagentTypeService;
import com.logictech.lims.entity.ReagentType;
import com.logictech.lims.dao.ReagentTypeDao;
import com.logictech.lims.dto.ReagentTypeDto;

@Service("reagentTypeService")
public class ReagentTypeServiceImpl implements ReagentTypeService {
	@Resource
	private ReagentTypeDao reagentTypeDao;

	@Resource
	private LogService logService;
	
	@Override
	public void doAdd(ReagentType reagentType) {
		reagentTypeDao.add(reagentType);
		logService.doAdd("1",reagentTypeDao.get(reagentType.getId()));
	}

	@Override
	public void doEdit(ReagentType reagentType) {
		reagentTypeDao.update(reagentType);
		logService.doAdd("2",reagentTypeDao.get(reagentType.getId()));
	}

	@Override
	public void doDelete(String id) {
		ReagentType reagentType = reagentTypeDao.get(id);
		logService.doAdd("3",reagentType);
		reagentType.setDeleteFlag("1");
		reagentTypeDao.update(reagentType);
	}

	@Override
	public ReagentType queryById(String id) {
		ReagentType reagentType  = reagentTypeDao.get(id);
		return reagentType;
	}

	@Override
	public PageList<ReagentTypeDto> queryPageList(PageQuery<ReagentTypeDto> pageQuery) {
		PageList<ReagentTypeDto> result = new PageList<ReagentTypeDto>();
		Integer itemCount = reagentTypeDao.count(pageQuery);
		List<ReagentTypeDto> list = reagentTypeDao.queryPageList(pageQuery,itemCount);
		Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
		result.setPagenation(pagenation);
		result.setValues(list);
		return result;
	}
	
	@Override
	public List<ReagentTypeDto> queryAll(String name) {
		return reagentTypeDao.queryAll(name);
	}

	@Override
	public List<ReagentTypeDto> queryList(PageQuery<ReagentTypeDto> pageQuery) {
		return reagentTypeDao.queryList(pageQuery);
	}
	
}
